/**
 * The MIT License (MIT)
 * Copyright (c) 2020 铭软科技(mingsoft.net)
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:

 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.

 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package net.mingsoft.cms.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.basic.annotation.LogAnn;
import net.mingsoft.basic.bean.EUListBean;
import net.mingsoft.basic.constant.e.BusinessTypeEnum;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.cms.biz.IKeyTagBiz;
import net.mingsoft.cms.entity.ContentEntity;
import net.mingsoft.cms.entity.ContentShuffleTitleEntity;
import net.mingsoft.cms.entity.KeyTagEntity;
import springfox.documentation.annotations.ApiIgnore;

/**
 * Key Tag管理控制层
 */
@Api(value = "热点云标签Tag接口")
@Controller("cmsKeyTagAction")
@RequestMapping("/${ms.manager.path}/cms/keyTag")
public class KeyTagAction extends BaseAction {
	
	Logger logger = LoggerFactory.getLogger(KeyTagAction.class);
	/**
	 * 注入Tag业务层
	 */	
	@Autowired
	private IKeyTagBiz contentBiz;

	/**
	 * 返回主界面main
	 */
	 @GetMapping("/main") 
	 public String main(HttpServletResponse response,HttpServletRequest request){ 
		 return "/cms/keyTag/main"; 
	 }
	 
	/**
	 * 查询Tag标题列表
	 * @param content Tag实体
	 */
	@ApiOperation(value = "查询Tag列表接口")
	@ApiImplicitParams({
    	@ApiImplicitParam(name = "title", value = "Tag标题", required =false,paramType="query"),
    })
	@RequestMapping("/list")
	@ResponseBody
	public ResultData list(@ModelAttribute @ApiIgnore KeyTagEntity content, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model, BindingResult result) {
		BasicUtil.startPage();
		List contentList = contentBiz.query(content);
		ResultData res = ResultData.build().success(new EUListBean(contentList,(int) BasicUtil.endPage(contentList).getTotal()));
		return res;
	}
	
	/**
	 * 返回编辑界面content_form
	 */
	@GetMapping("/form")
	public String form(@ModelAttribute ContentEntity content, HttpServletResponse response, HttpServletRequest request, ModelMap model){
		model.addAttribute("appId", BasicUtil.getApp().getAppId());
		return "/cms/keyTag/form";
	}
	
	@ApiOperation(value = "保存Tag标题列表接口")
	 @ApiImplicitParams({
    	@ApiImplicitParam(name = "contentTitles", value = "Tag标题", required =true,paramType="query"),
	})
	/**
	* 保存Tag标题
	* @param content Tag实体
	*/
	@PostMapping("/save")
	@ResponseBody
	@LogAnn(title = "保存Tag标题", businessType = BusinessTypeEnum.INSERT)
	@RequiresPermissions("cms:keyTag:save")
	public ResultData save(@RequestBody List<String> contentTitles, HttpServletResponse response, HttpServletRequest request) {
		contentBiz.save(contentTitles);
		return ResultData.build().success();
	}
	
	/**
	 * @param contents Tag实体
	 */
	@ApiOperation(value = "批量删除Tag标题列表接口")
	@PostMapping("/delete")
	@ResponseBody
	@LogAnn(title = "删除Tag标题", businessType = BusinessTypeEnum.DELETE)
	@RequiresPermissions("cms:keyTag:del")
	public ResultData delete(@RequestBody List<String> ids, HttpServletResponse response, HttpServletRequest request) {
		contentBiz.removeByIdss(ids);
		return ResultData.build().success();
	}
	
}
